package com.example.lawyer.databind.assembly;


import android.content.Intent;
import android.os.Build;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.annotation.RequiresApi;
import androidx.databinding.BindingAdapter;
import androidx.databinding.ObservableField;

import com.example.lawyer.BR;
import com.example.lawyer.R;
import com.example.lawyer.adapter.CurrentAdapters;
import com.example.lawyer.databind.itemview.LawterListItemData;
import com.example.lawyer.databind.itemview.NewListViewData;
import com.example.lawyer.factory.AutoHeightListTool;

import java.util.List;

public class TypeNewListData {

    public ObservableField<List<LawterListItemData>> newlistdata = new ObservableField<>();

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    @BindingAdapter("setadapter")
    public static void SetAdapter(View view,List<LawterListItemData> data)
    {
        if(data==null)
        {
            return;
        }
        CurrentAdapters<LawterListItemData> newListViewDataCurrentAdapters = new CurrentAdapters<>(data, R.layout.item_lawyer_view, com.example.lawyer.BR.lawterlistitemdata);
        ListView listView = (ListView) view;
        listView.setAdapter(newListViewDataCurrentAdapters);
        new AutoHeightListTool().ListViewHeightTool(listView,1);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                System.out.println("点击有效");
                Intent intent = new Intent();
                intent.setAction("MainLaye");
                parent.getContext().startActivity(intent);
            }
        });


    }


}
